﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ECCIT.Report.Excel
{
    public class HtmlTemplateElement
    {
        private int _prefixBlankCount;
        private string _start;
        private string _end;
        private int _index;
        private string _innerText;

        public int PrefixBlankCount
        {
            get { return _prefixBlankCount; }
            set { _prefixBlankCount = value; }
        }

        public string Start
        {
            get { return _start; }
            set { _start = value; }
        }

        public string End
        {
            get { return _end; }
            set { _end = value; }
        }

        public int Index
        {
            get { return _index; }
            set { _index = value; }
        }

        public virtual string InnerText
        {
            get { return _innerText; }
            set { _innerText = value; }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();
            int blankCount = _prefixBlankCount;
            while (blankCount > 0)
            {
                builder.Append(" ");
                blankCount--;
            }

            builder.Append(_start).Append(InnerText).Append(_end);

            return builder.ToString();
        }

        public virtual HtmlTemplateElement Clone()
        {
            HtmlTemplateElement element = new HtmlTemplateElement(_index, _start, _end, _prefixBlankCount);
            element.InnerText = InnerText;
            return element;
        }

        public HtmlTemplateElement(string start, string end) : this(0, start, end, 0) { }
        public HtmlTemplateElement(int index, string start, string end) : this(index, start, end, 0) { }
        public HtmlTemplateElement(string start, string end, int prefixBlankCount) : this(0, start, end, prefixBlankCount) { }
        public HtmlTemplateElement(int index, string start, string end, int prefixBlankCount)
        {
            _index = index;
            _start = start;
            _end = end;
            _prefixBlankCount = prefixBlankCount;
        }
    }
}
